struct directional_light {
	vec3 direction;			
	vec3 halfplane;			
	vec4 ambient_color;
	vec4 diffuse_color;
	vec4 specular_color;
};

struct material_properties {
	vec4 ambient_color;
	vec4 diffuse_color;
	vec4 specular_color;
	float specular_exponent;
};

const float c_zero = 0.0;
const float c_one = 1.0;

uniform mat4 u_mvp_matrix;
uniform mat4 u_modelview_matrix;
uniform mat4 u_inv_modelview_matrix;

uniform material_properties u_material;
uniform directional_light u_light;

attribute vec4 a_position;
attribute vec3 a_normal;
attribute vec4 a_color;

varying vec4 v_color;


vec4 directional_light(vec3 normal) {
vec4	computed_color = vec4(c_zero, c_zero, c_zero, c_zero);
return computed_color;
}


void main() {	
vec4 temp_normal = vec4(a_normal, 0.0);
temp_normal = normalize(temp_normal);
temp_normal = u_inv_modelview_matrix * temp_normal;
vec3 normal = vec3(temp_normal.x, temp_normal.y, temp_normal.z);

normal = normalize(normal);

vec4 computed_color = vec4(c_zero, c_zero, c_zero, 1.0);
float ndotl;		// dot product of normal & light direction
float ndoth;		// dot product of normal & half-plane vector
ndotl = max(c_zero, dot(normal, u_light.direction));
ndoth = max(c_zero, dot(normal, u_light.halfplane));
computed_color += (u_light.ambient_color * u_material.ambient_color);
computed_color += (ndotl * u_light.diffuse_color * u_material.diffuse_color);
if (ndoth > c_zero)
	{
		computed_color += (pow(ndoth, u_material.specular_exponent) * u_material.specular_color * u_light.specular_color);
	}
			


gl_Position = u_mvp_matrix * a_position;
v_color = computed_color;
}
